var express = require('express');
var router = express.Router();
const { rootModel } = require('../model/cpp_model')

//注册登录账号
router.post('/oneLogin', async (req, res) => {
  let body = req.body;
  let result = await rootModel.findOne({ phone: body['phone'] })
  if (result) return res.send({ code: 201, msg: `登录成功,欢迎 ${result['nickname'] ? result['nickname'] : result['phone']}` })
  await rootModel.create(body)
  return res.send({ code: 201, msg: `欢迎您,新用户~` })
})
//登录账号
router.post('/login', async (req, res) => {
  let body = req.body;
  let result = await rootModel.findOne({ phone: body['phone'] })
  console.log(result,'111');
  // if (result) return res.send({ code: 201, msg: `登录成功,欢迎 ${result['nickname'] ? result['nickname'] : result['phone']}` })
  // await rootModel.create(body)
  // return res.send({ code: 201, msg: `欢迎您,新用户~` })
})

//实验
router.get('/a', async (req, res) => {
  let list = ['蛮棒的'] 
  // console.log('执行了');
  res.send(list)
})



module.exports = router;